package com.heima.wemedia.test;

import com.heima.common.constants.message.HotArticleConstants;
import com.heima.common.util.JsonUtils;
import com.heima.model.article.dtos.ArticleBehaviorMsg;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@SpringBootTest
@RunWith(SpringRunner.class)
public class SendBehaviorMsg {

    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @Test
    public void sendMsg() throws InterruptedException {
        String topic = HotArticleConstants.HOT_ARTICLE_SCORE_STREAM_TOPIC;

        for(int i=0;i<5;i++) {
            ArticleBehaviorMsg view = new ArticleBehaviorMsg();
            view.setNum(1);
            view.setArticleId(1627877337951424513L);
            view.setType(ArticleBehaviorMsg.ArticleBehaviorType.VIEWS);
            String viewsMsg = JsonUtils.toString(view);
            kafkaTemplate.send(topic, viewsMsg);

            ArticleBehaviorMsg likes = new ArticleBehaviorMsg();
            likes.setNum(1);
            likes.setArticleId(1627877337951424513L);
            likes.setType(ArticleBehaviorMsg.ArticleBehaviorType.LIKES);
            String likeMsg = JsonUtils.toString(likes);
            kafkaTemplate.send(topic, likeMsg);

            Thread.sleep(1000);
        }

        for(int i=0;i<50;i++) {
            ArticleBehaviorMsg view = new ArticleBehaviorMsg();
            view.setNum(1);
            view.setArticleId(1597495319494496257L);
            view.setType(ArticleBehaviorMsg.ArticleBehaviorType.VIEWS);
            String viewsMsg = JsonUtils.toString(view);
            kafkaTemplate.send(topic, viewsMsg);

            ArticleBehaviorMsg likes = new ArticleBehaviorMsg();
            likes.setNum(1);
            likes.setArticleId(1597495319494496257L);
            likes.setType(ArticleBehaviorMsg.ArticleBehaviorType.LIKES);
            String likeMsg = JsonUtils.toString(likes);
            kafkaTemplate.send(topic, likeMsg);


            ArticleBehaviorMsg comment = new ArticleBehaviorMsg();
            comment.setNum(1);
            comment.setArticleId(1597495319494496257L);
            comment.setType(ArticleBehaviorMsg.ArticleBehaviorType.COMMENT);
            String commentMsg = JsonUtils.toString(comment);
            kafkaTemplate.send(topic, commentMsg);


            ArticleBehaviorMsg coll = new ArticleBehaviorMsg();
            coll.setNum(1);
            coll.setArticleId(1597495319494496257L);
            coll.setType(ArticleBehaviorMsg.ArticleBehaviorType.COLLECTION);
            String collectionMsg = JsonUtils.toString(coll);
            kafkaTemplate.send(topic, collectionMsg);

            Thread.sleep(1000);
        }

    }
}
